<?php
class PageController extends Zend_Controller_Action
{
	private $t;
	private $hash;

	public function preDispatch()
	{
		$this->t = Zend_Registry::get('Zend_Translate');
		$this->view->t = $this->t;
	}

	public function viewAction()
	{
		$id = (int) $this->_request->getParam('id');
		$languageId = Zend_Registry::get('language');

		$pages = new Pages();
		$pagesL10N = new PagesL10N();

		$page = $pages->fetchRow("`id` = '{$id}'");
		$pageL10N = $pagesL10N->fetchRow(array("`pageId` = '{$id}'", "`languageId` = '{$languageId}'"));

		if($pageL10N == NULL) {
			$this->view->title = $this->t->_('this page is not available in this language');
		} else {
			$this->view->title = $pageL10N->name;
			$this->view->page = $page;
			$this->view->pageL10N = $pageL10N;
		}
	}

	public function sitemapAction()
	{
		$languageId = Zend_Registry::get('language');
		$pages = new Pages();

		$this->view->title = $this->t->_('sitemap');
		$this->view->pages = $pages->generateTree($languageId);
	}
}